package by.grsu.epam.dao.entitiesdao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import by.grsu.epam.dao.GenericDAOImpl;
import by.grsu.epam.dao.entitiesdao.PayCardDAO;
import by.grsu.epam.domain.account.PayCard;

@Repository
public class PayCardDAOImpl extends GenericDAOImpl<PayCard, Long> implements PayCardDAO {
	
	public PayCardDAOImpl(){
		super(PayCard.class);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<PayCard> findBySubscriberId(Long subscriberId) {
		Criteria cr = getSession().createCriteria(PayCard.class, "paycard");
		cr.add(Restrictions.like("paycard.subscriber.id", subscriberId));
        return (List<PayCard>) cr.list();
	}

	@Override
	public PayCard findBySerialNumber(String serial) {
		Criteria cr = getSession().createCriteria(PayCard.class);
		cr.add(Restrictions.like("serialNumber", serial));
		return (PayCard) cr.uniqueResult();
	}
}
